import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: dell
 * Date: 2023-01-14
 * Time: 9:21
 */
public class Game {
    private static final String[] suits = {"♥","♣","♦","♠"};
    public List<Poker> buyPoker(){  //买扑克，生成54张牌
        List<Poker> pokers = new ArrayList<>();//这些牌叫pokers,就是都存在pokers里面
        for(int i = 0;i < 4; i++){
            for(int j = 1; j <= 13; j++){
                Poker poker = new Poker(suits[i],j);//生成一张牌
                pokers.add(poker);

            }
        }
        return pokers;
        //也就是通过这个方法，我可以买回来52张牌
    }

    public void shuffle(List<Poker> pokers){  //洗牌

        for(int i = pokers.size()-1; i > 0; i--){ //52张牌，51下标是不越界的
            Random random = new Random();//每次生成的随机数
            int index = random.nextInt(i);//生成的下标
            swap(pokers,i,index);
        }
    }
    private void swap(List<Poker> pokers,int i,int j){
        Poker tmp = pokers.get(i);//交换
        pokers.set(i,pokers.get(j));
        pokers.set(j,tmp);//通过get、set方法进行交换
    }

    public List<List<Poker>> game(List<Poker>pokers){
        List<List<Poker>> hand = new ArrayList<>();

        List<Poker>hand1 = new ArrayList<>();
        List<Poker>hand2 = new ArrayList<>();
        List<Poker>hand3 = new ArrayList<>();

        hand.add(hand1);
        hand.add(hand2);
        hand.add(hand3);

        //最外层循环 控制 轮数  二维数组（才能使三个人之间存在关联关系）
        for(int i = 0;i < 5; i++){
            for(int j = 0;j < 3;j++){
                //删除哪个下标的值  会把哪个下标的值进行返回
                Poker removePoker = pokers.remove(0);
                hand.get(j).add(removePoker);
            }
        }
        return hand;
    }

}
